import {Injectable} from '@angular/core';
import {AppConfig} from '../config';
import {AlarmCategory} from '../entity/alarm-category.model';
import {InterceptorService} from './interceptor/interceptor-service';

@Injectable()
export class AlarmCategoryService {
  private readonly param = 'alarmCategorys';

  private get url(): string {
    return `${AppConfig.APP_RESTFUL}/${this.param}`;
  }


  constructor(private http: InterceptorService) {
  }

  /**
   * 获取报警分类（报警、告警）
   */
  getAlarmCategorys(): Promise<AlarmCategory[]> {
    return this.http.get(this.url)
      .toPromise()
      .then(response => response.data as AlarmCategory[])
      .catch(this.handleError);

  }

  private handleError(error: any): Promise<any> {
    // console.error('An error occurred', error); // for demo purposes only
    return Promise.reject(error.message || error);
  }

}


// WEBPACK FOOTER //
// ./src/app/service/alarm-category.service.ts
